<?php

/**
 * Author: Artem Azarov <bel-azar@ya.ru>
 * Date: 3/24/12
 * Time: 8:31 PM
 */
class WebUser extends CWebUser {
    private $_model = null;

    function getRole() {
        if($user = $this->getModel()){
            return $user->role;
        }
    }

    private function getModel() {
        if (!$this->isGuest && $this->_model === null){
            $this->_model = User::model()->findByPk($this->id, array('select' => 'role'));
        }
        return $this->_model;
    }

    /**
     * Check - is users administrator
     * @return bool
     */
    public function getIsAdmin() {
        return Yii::app()->user->getRole() == User::ROLE_ADMIN;
    }

}